//
//  KBMusicListTableCell.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "KBMusicListTableCell.h"

@implementation KBMusicListTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    // 图片
    _albumCoverUrl290 = [[UIImageView alloc] init];
    [self.contentView addSubview:_albumCoverUrl290];
    [_albumCoverUrl290 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(12);
        make.size.mas_equalTo(CGSizeMake(80, 80));
        
    }];
    // 标题
    _title = [[UILabel alloc] init];
    _title.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:_title];
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_albumCoverUrl290.mas_top);
        make.left.equalTo(_albumCoverUrl290.mas_right).offset(4);
        make.width.mas_equalTo(230);
        make.height.mas_equalTo(22);
        
    }];
    // 内容
    _intro = [[UILabel alloc] init];
    _intro.font = [UIFont systemFontOfSize:14];
    _intro.textColor = [UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
    [self.contentView addSubview:_intro];
    [_intro mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_title.mas_bottom).offset(2);
        make.left.equalTo(_title.mas_left).offset(5);
        make.width.mas_equalTo(235);
        make.height.mas_equalTo(22);
        
    }];
    
    // 播放次数(图)
    UIImageView *playtime = [[UIImageView alloc] init];
    playtime.image = [UIImage imageNamed:@"sound_playtimes@2x.png"];
    [self.contentView addSubview:playtime];
    [playtime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_intro.mas_bottom).offset(5);
        make.left.mas_equalTo(_intro.mas_left).offset(3);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(10);
    }];
    
    // 播放次数
    _playsCounts = [[UILabel alloc] init];
    _playsCounts.font = [UIFont systemFontOfSize:13];
    _playsCounts.textColor = [UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
    [self.contentView addSubview:_playsCounts];
    [_playsCounts mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(playtime.mas_top).offset(-5);
        make.left.mas_equalTo(playtime.mas_right).offset(5);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
        
    }];
    
    // 集数(图)
    UIImageView *setImage = [[UIImageView alloc] init];
    setImage.image = [UIImage imageNamed:@"find_hotUser_sounds@2x.png"];
    [self.contentView addSubview:setImage];
    
    [setImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(playtime.mas_top);
        make.left.mas_equalTo(_playsCounts.mas_right).offset(10);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(10);
    }];
    
    // 集数
    _tracksCounts = [[UILabel alloc] init];
    _tracksCounts.font = [UIFont systemFontOfSize:13];
    _tracksCounts.textColor = [UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
    [self.contentView addSubview:_tracksCounts];
    [_tracksCounts mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(_playsCounts.mas_top);
        make.left.mas_equalTo(setImage.mas_right).offset(5);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
        
    }];
}

- (void)setModel:(KBMusicListModel *)model
{
    _title.text = model.title;
    _intro.text = model.intro;
    
    NSURL *url = [NSURL URLWithString:model.albumCoverUrl290];
    [_albumCoverUrl290 sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    
    CGFloat number = model.playsCounts /10000;
    _playsCounts.text = [NSString stringWithFormat:@"%.lf万", number];
    
    _tracksCounts.text = [NSString stringWithFormat:@"%ld集", model.tracksCounts];

}



























- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
